﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Common="http://imagin.tech/imagin/common"
    xmlns:Controls.Common="clr-namespace:Imagin.Controls.Common;assembly=Imagin.Controls.Common">
    <Common:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

    <Style x:Key="{x:Type ToolBar}" TargetType="{x:Type ToolBar}">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Background" Value="{DynamicResource Brush.ToolBar.Background}" />
        <Setter Property="BorderBrush" Value="{DynamicResource Brush.ToolBar.Border}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToolBar}">
                    <Border
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
						Padding="{TemplateBinding Padding}">
                        <Grid 
                            x:Name="Grid" 
                            SnapsToDevicePixels="true">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid
                                KeyboardNavigation.TabIndex="1" 
                                KeyboardNavigation.TabNavigation="Local">
                                <ToolBarPanel 
                                    x:Name="PART_Panel"
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
									Margin="0,1,2,2"
									IsItemsHost="true"
									SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </Grid>
                            <Grid 
                                Grid.Column="1"
                                x:Name="PART_OverflowGrid" 
                                HorizontalAlignment="Right">
                                <Controls.Common:MaskedToggleButton 
                                    x:Name="PART_OverflowButton"
								    ClickMode="Press"
								    FocusVisualStyle="{x:Null}" 
                                    IsChecked="{Binding IsOverflowOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                    RenderTransformOrigin="0.5,0.5"
                                    Source="/Images/DoubleArrowDown.png" 
								    Visibility="{TemplateBinding HasOverflowItems, Converter={StaticResource BooleanToVisibilityConverter}}">
                                    <Controls.Common:MaskedToggleButton.RenderTransform>
                                        <RotateTransform Angle="-90"/>
                                    </Controls.Common:MaskedToggleButton.RenderTransform>
                                </Controls.Common:MaskedToggleButton>
                                <Popup 
                                    x:Name="PART_OverflowPopup"
								    AllowsTransparency="true"
								    Focusable="false"
								    IsOpen="{Binding IsOverflowOpen, RelativeSource={RelativeSource TemplatedParent}}"
								    Placement="Bottom"
								    PopupAnimation="Slide"
								    StaysOpen="True">
                                    <Border 
                                        Background="{DynamicResource Brush.ContextMenu.Background}" 
                                        BorderBrush="{DynamicResource Brush.ContextMenu.Border}" 
                                        BorderThickness="1" 
                                        Padding="5" 
                                        Margin="5,0,5,5">
                                        <!--
                                        <Controls:AdvancedToolBarOverflowPanel 
                                            x:Name="PART_ToolBarOverflowPanel"
										    Focusable="True"
										    FocusVisualStyle="{x:Null}"
										    KeyboardNavigation.DirectionalNavigation="Cycle"
										    KeyboardNavigation.TabNavigation="Cycle"
										    Margin="2"
										    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
										    WrapWidth="200" />
                                        -->
                                        <Border.Effect>
                                            <DropShadowEffect Color="{DynamicResource Brush.ContextMenu.DropShadow}" Opacity="0.40" BlurRadius="6" ShadowDepth="3"/>
                                        </Border.Effect>
                                    </Border>
                                </Popup>
                            </Grid>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="PART_OverflowPopup" Property="HasDropShadow" Value="True" />
                        <Trigger Property="Orientation" Value="Vertical">
                            <Setter TargetName="Grid" Property="Margin" Value="1,3,1,1" />
                            <Setter TargetName="PART_Panel" Property="Margin" Value="1,0,2,2" />
                            <Setter TargetName="PART_OverflowGrid" Property="HorizontalAlignment" Value="Stretch" />
                            <Setter TargetName="PART_OverflowGrid" Property="VerticalAlignment" Value="Bottom" />
                            <Setter TargetName="PART_OverflowPopup" Property="Placement" Value="Right" />
                            <Setter TargetName="PART_OverflowButton" Property="Style">
                                <Setter.Value>
                                    <Style TargetType="{x:Type ToggleButton}">
                                        <Setter Property="Background" Value="{StaticResource ToolBarToggleButtonVerticalBackground}" />
                                        <Setter Property="MinHeight" Value="0" />
                                        <Setter Property="MinWidth" Value="0" />
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                    <Border x:Name="Bd"
									                    Background="{TemplateBinding Background}"
									                    CornerRadius="0,0,3,3"
									                    SnapsToDevicePixels="true">
                                                        <Canvas Width="7"
										                    Height="6"
										                    Margin="2,7,2,2"
										                    HorizontalAlignment="Right"
										                    VerticalAlignment="Bottom"
										                    SnapsToDevicePixels="true">
                                                            <Path Data="M 1.5 1 L 1.5 6" Stroke="White" />
                                                            <Path Data="M 0.5 0 L 0.5 5" Stroke="{TemplateBinding Foreground}" />
                                                            <Path Data="M 3.5 0.5 L 7 3.5 L 4 6.5 Z" Fill="White" />
                                                            <Path Data="M 3 -0.5 L 6 2.5 L 3 5.5 Z" Fill="{TemplateBinding Foreground}" />
                                                        </Canvas>
                                                    </Border>
                                                    <ControlTemplate.Triggers>
                                                        <Trigger Property="IsMouseOver" Value="true">
                                                            <Setter TargetName="Bd" Property="Background" Value="{StaticResource ToolBarButtonHover}" />
                                                        </Trigger>
                                                        <Trigger Property="IsEnabled" Value="false">
                                                            <Setter Property="Foreground" Value="{StaticResource ToolBarGripper}" />
                                                        </Trigger>
                                                    </ControlTemplate.Triggers>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type ToolBarTray}" TargetType="{x:Type ToolBarTray}">
        <Setter Property="Background" Value="{DynamicResource Brush.ToolBarTray.Background}" />
        <Setter Property="Margin" Value="7,0,0,0" />
    </Style>
</ResourceDictionary>